package com.lihepeng.leecode.chart;

import java.util.ArrayList;
import java.util.List;

/**
 * 无向图 定点和标构成
 * <p>
 * 有向图 定点和有向边构成
 * <p>
 * 完全图 任意两个定点之间存在边的图叫做完全图，
 *
 * @param <T>
 */
public class GraphNode<T> {
    T data;
    List<GraphNode<T>> neighborList;
    boolean visited;

    public GraphNode(T data) {
        this.data = data;
        this.neighborList = new ArrayList<>();
        this.visited = false;
    }

    // 使用递归的方案将里面的节点编程未访问
    public void restoreVisited(GraphNode<T> node) {
        if (node.visited) {
            node.visited = false;
        }
        List<GraphNode<T>> neighbors = node.neighborList;
        neighbors.forEach(neighbor -> {
            restoreVisited(neighbor);
        });
    }


}
